package com.my.test.thread.atomic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

public class TestAtomicIntegerFieldUpdater {


    public static void main(String[] args) {
        /*AtomicIntegerFieldUpdater<User> aa =
                AtomicIntegerFieldUpdater.newUpdater(User.class, "age");*/


        // 原子更新引字段类
        AtomicIntegerFieldUpdater<User> a = AtomicIntegerFieldUpdater.
                newUpdater(User.class, "age");

        User conan = new User("conan", 10);
        System.out.println(a.getAndDecrement(conan));
        System.out.println(a.get(conan));


    }

    static class User {
        private String name;

        public volatile int age;

        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
